<?php
namespace app\admin\controller;
use think\Controller;
use think\Validate;
use think\Db;
use think\Session;
class Login extends controller
{  

	
    
	public function login()
    {//登录 
		
		 $post=input("post.");//获取post数据'
	 
		  if($post){
			   
	         if($post['name']==''){ exit(json_encode(array('status'=>'0','msg'=>'用户名不能为空')));}
			  if($post['pwd']==''){exit(json_encode(array('status'=>'0','msg'=>'密码不能为空')));}
			 if(!captcha_check($post['verify'])){exit(json_encode(array('status'=>'0','msg'=>'验证码错误')));}
			$user= Db::name('admin')->where('username',$post['name'])->find();
			if(!$user){exit(json_encode(array('status'=>'0','msg'=>'用户名错误')));}
			if(md5($post['pwd'])!=$user['password']){exit(json_encode(array('status'=>'0','msg'=>'密码错误')));}
			Session::set('adminid',$user['id']);
			exit(json_encode(array('status'=>'1','url'=>'/admin/index')));


		 }else{
		  
          $config= Db::name('config')->find();$this->assign("config",$config);
		  return $this->fetch();
		  }
    }
	public function orderapi(){
	
	$num=projectfh();
     echo $num;
	}


	public function logout(){
	Session::set('adminid','');
	header('Location: index');
	}
}
